import { useEffect, useRef } from "react";


// 只在挂载时运行
export const useMount = (callback: () => void) => {
  useEffect(() => {
    callback();
     // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
};

// 用来返回组件的挂载状态
export const useMountedRef = () => {
    const mountedRef = useRef(false);
    useEffect(() => {
      mountedRef.current = true;
      return () => {
        mountedRef.current = false;
      };
    });
    return mountedRef;
  };
  
